<!--消息配置审核-->
<template>
  <div class="app-container">
    <ht-search-form
      v-show="showSearch"
      :dictMap="dictMap"
      :labelWidth="100"
      :queryParams="queryParams"
      :outputQueryParams="queryParams"
      :formOptions="formOptions"
      :advOptions="[]"
      :defaultEventKey="defaultEventKey"
    ></ht-search-form>
    <ht-table
      ref="dataTable"
      rowKey="id"
      :showSerialNumber="false"
      :multi-select="false"
      :dictMap="dictMap"
      :reqConfig="reqConfig"
      :queryParams="queryParams"
      :tableBindColumns="tableBindColumns"
      :opButtonList="opButtonList"
    >
      <template v-slot:operate>
        <el-table-column label="操作" align="left" width="100px" fixed="right" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <ht-button-group
              :buttonList="[
                {
                  label: '明细',
                  doFunc: () => {
                    detail(scope.row);
                  },
                },
              ]"
            />
          </template>
        </el-table-column>
      </template>
    </ht-table>

    <msg-conf-approve-dialog ref="msgConfApproveDialog" @editComplete="editComplete"></msg-conf-approve-dialog>
  </div>
</template>
<script>
import {
  msgConfApproveUrlConfig,
  getMonitorConfList,
  getMsgGroupList,
  getEventTypeName,
} from "@/api/cnaps/bizMng/msgConf.js";
import { listPageMixin } from "@/libs/listPageMixin";
import MsgConfApproveDialog from "./dialog";

export default {
  name: "msgConf_approve",
  mixins: [listPageMixin],
  components: {
    MsgConfApproveDialog,
  },
  props: {},
  data() {
    return {
      reqConfig: msgConfApproveUrlConfig,
      defaultEventKey: "",
      eventTypeList: [],
      msgGroupList: [],
      //数据字典
      searchFormDictList: ["ON_OFF_STATUS", "MSG_SEND_TYPE", "CHECK_STATUS"],
      // 遮罩层
      loading: true,
      // 弹出层标题
      title: "",
      showSearch: true,
      // 日期范围
      dateRange: [],
      // 查询参数
      queryParams: {
        eventType:"",
        sendType:"",
        isUse:"",
      },
      formOptions: [],
      opButtonList: () => {
        return [];
      },
      tableBindColumns: [
        {
          label: `事件类型`,
          prop: "eventType",
          width: "200px",
          align: "center",
          formatter: (row) => {
            if (!row.eventType) {
              return "-";
            }
            return row.eventNm;
          },
        },
        { label: `启用标识`, prop: "isUse", align: "center", dictCode: "ON_OFF_STATUS" },

        // { label: `节假日开关`, prop: "holidayFlag", width: "120px", align: "center"},
        // { label: `发送开始时间`, prop: "sendStartDt", width: "120px", align: "center"},
        // { label: `发送结束时间`, prop: "sendEndDt", width: "120px", align: "center"},
        {
          label: `通知类型`,
          prop: "sendType",
          width: "200px",
          align: "center",
          formatter(row) {
            let sendTypeName = "";
            let sendType = row.sendType;
            if (sendType === "01") {
              sendTypeName = "01-邮件通知";
            } else if (sendType === "02") {
              sendTypeName = "02-短信通知";
            } else if (sendType === "01,02" || sendType === "02,01") {
              sendTypeName = "01-邮件通知,02-短信通知";
            }
            return sendTypeName;
          },
        },
        {
          label: `邮件接收人小组`,
          prop: "mailRecGroup",
          width: "300px",
          align: "center",
          formatter(row) {
            return row.mailRecGroupNm;
          },
        },
        {
          label: `邮件抄送人小组`,
          prop: "mailCopyGroup",
          width: "300px",
          align: "center",
          formatter(row) {
            return row.mailCopyGroupNm;
          },
        },
        {
          label: `短信接收人小组`,
          prop: "smsRecGroup",
          width: "300px",
          align: "center",
          formatter(row) {
            return row.smsRecGroupNm;
          },
        },
        { label: `录入操作员`, prop: "creator",  width: "200px",align: "center" },
        { label: `录入时间`, prop: "createdTime", width: "200px", align: "center", type: "date" },
        { label: `维护操作员`, prop: "updator",  width: "200px",align: "center" },
        { label: `维护时间`, prop: "updatedTime", width: "200px", align: "center", type: "date" },
        { label: `审批状态`, prop: "checkStatus", align: "center", dictCode: "CHECK_STATUS",fixed: "right", },
      ],
    };
  },
  mounted() {
    this.formOptions = [
      {
        type: "input",
        prop: "eventType",
        defaultAttr: {
          label: "事件类型",
          placeholder: "请输入事件类型",
        },
      },
      {
        type: "dict",
        dict: "MSG_SEND_TYPE",
        prop: "sendType",
        defaultAttr: {
          label: "通知类型",
          placeholder: "请选择通知类型",
        },
      },
      {
        type: "dict",
        dict: "ON_OFF_STATUS",
        prop: "isUse",
        defaultAttr: {
          label: "启用标识",
          placeholder: "请选择启用标识",
        },
      },
      // {
      //   type: "dict",
      //   dict: "CHECK_STATUS",
      //   prop: "checkStatus",
      //   defaultAttr: {
      //     label: "审批状态",
      //     placeholder: "请选择审批状态",
      //   },
      // },
    ];
    this.initEventTypeList();
    this.initMsgGroupList();
  },
  methods: {
    /** todo 查询当天操作员的交易记录 */
    getList() {
      this.doQuery();
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    detail(row) {
      console.log("this.$refs.msgConfApproveDialog", this.$refs.msgConfApproveDialog);
      this.$refs.msgConfApproveDialog.show(row);
    },
    editComplete(state) {
      console.log("editComplete", state);
      if (state == true) {
        this.getList();
      }
    },

    //事件类型名称转换
    getEventTypeName(row) {
      let eventTypeName = "";
      getEventTypeName(row).then((res) => {
        if (res.code === "S") {
          eventTypeName = res.result;
        }
      });
      return eventTypeName;
    },

    //初始化获取监控事件列表
    initEventTypeList() {
      getMonitorConfList(this.queryParams).then((res) => {
        if (res.code === "S") {
          const arr = [];
          const list = res.result || [];
          list.length &&
            list.forEach((v) => {
              arr.push({
                value: v.monitorId,
                text: v.eventNm,
              });
            });
          this.eventTypeList = arr;
        }
      });
    },

    //初始化获取消息分组
    initMsgGroupList() {
      getMsgGroupList(this.queryParams).then((res) => {
        if (res.code === "S") {
          const arr = [];
          const list = res.result || [];
          list.length &&
            list.forEach((v) => {
              arr.push({
                value: v.groupId,
                text: v.groupNm,
              });
            });
          this.msgGroupList = arr;
        }
      });
    },
  },
};
</script>
<style>
.label-header-msg {
  font-weight: bold;
}
</style>
